package system.company.base.Objects;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import system.company.actor.Ordinary_Staff.BaseHibernateDAO;

/**
 * A data access object (DAO) providing persistence and search support for
 * Object_AttendRecord entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see system.company.base.Objects.Object_AttendRecord
 * @author MyEclipse Persistence Tools
 */

public class Object_AttendRecordDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory
			.getLog(Object_AttendRecordDAO.class);
	// property constants
	public static final String _ID = "ID";
	public static final String NAME = "name";
	public static final String _STR_TIME = "Str_time";
	public static final String STATUS = "status";
	public static final String LATE_ABSENCE_LEAVEEARLY = "late_absence_leaveearly";
	public static final String DEPARTMENT = "department";

	public void save(Object_AttendRecord transientInstance) {
		log.debug("saving Object_AttendRecord instance");
		try {
			Transaction tran = getSession().getTransaction();
			tran.begin();

			getSession().save(transientInstance);
			tran.commit();
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Object_AttendRecord persistentInstance) {
		log.debug("deleting Object_AttendRecord instance");
		try {
			Transaction tran = getSession().getTransaction();
			tran.begin();
			getSession().delete(persistentInstance);
			tran.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Object_AttendRecord findById(java.lang.Integer id) {
		log.debug("getting Object_AttendRecord instance with id: " + id);
		try {
			Object_AttendRecord instance = (Object_AttendRecord) getSession()
					.get("system.company.base.Objects.Object_AttendRecord", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Object_AttendRecord instance) {
		log.debug("finding Object_AttendRecord instance by example");
		try {
			List results = getSession().createCriteria(
					"system.company.base.Objects.Object_AttendRecord").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Object_AttendRecord instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Object_AttendRecord as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	public List findByTwoProperty(String propertyName_1,String propertyName_2, Object value_1, Object value_2) {
		log.debug("finding Object_AttendRecord instance with property: "
				+ propertyName_1 + ", value: " + value_1+"  "+ propertyName_2 + ", value: " + value_2);
		try {
			String queryString = "from Object_AttendRecord as model where model."
					+ propertyName_1 + "= ?"+" and model."+propertyName_2+"=?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value_1);
			queryObject.setParameter(1, value_2);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByIDAndTime(Object ID,Object Time)
	{
		return findByTwoProperty(_ID,_STR_TIME,ID,Time);
	}
	public List findByID(Object ID) {
		return findByProperty(_ID, ID);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByStr_time(Object Str_time) {
		return findByProperty(_STR_TIME, Str_time);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findByLate_absence_leaveearly(Object late_absence_leaveearly) {
		return findByProperty(LATE_ABSENCE_LEAVEEARLY, late_absence_leaveearly);
	}

	public List findByDepartment(Object department) {
		return findByProperty(DEPARTMENT, department);
	}

	public List findAll() {
		log.debug("finding all Object_AttendRecord instances");
		try {
			String queryString = "from Object_AttendRecord";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Object_AttendRecord merge(Object_AttendRecord detachedInstance) {
		log.debug("merging Object_AttendRecord instance");
		try {
			Object_AttendRecord result = (Object_AttendRecord) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Object_AttendRecord instance) {
		log.debug("attaching dirty Object_AttendRecord instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Object_AttendRecord instance) {
		log.debug("attaching clean Object_AttendRecord instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}